$(document).ready(init);
function init() {
	$("#act_login").bind("click",function() {
		var email = $("#email").val();
		var password = $("#password").val();
		var imgcode = $("#imgcode").val();

		$.ajax({
			type:"post",
			url:"index.php?Controller=Login&Action=LoginAct", 
			data:"email="+email+"&password="+password+"&imgcode="+imgcode,
			success:function (msg) {
				$("#area_userinfo").children().each(function(i){
					$(this).fadeOut("slow");
				});
				$("#area_userinfo").empty();
				$("#area_userinfo").prepend("<p>"+msg+"</p>");
				$("#area_userinfo").children().each(function(i){
					$(this).fadeIn("slow");
				});
				$.getScript("./scripts/control.js");
			}
		});
	
	});
	$("#act_register").bind("click",function() {
		var email = $("#reg_email").val();
		var password = $("#reg_password").val();
		$.ajax({
			type:"post",
			url:"index.php?Controller=Login&Action=RegisterAct", 
			data:"email="+email+"&password="+password,
			success:function (msg) {
				if(msg==true) {
					alert("注册成功");
					$('#dia_register').TransferTo({
						to:'js_register',
						className:'transferer2', 
						duration: 400
					}).hide();
				} else {
					$("#hexi_info").prepend("<p>"+msg+"</p>");
				}
			}
		});
	});

	$("#img_check").bind("click",function() {
		this.src="./index.php?controller=Login&action=imgcode&random="+Math.random();
	});
// 弹出可移动窗口窗口
	$('#js_register').bind('click',function() {
		if($('#dia_register').css('display') == 'none') {
					$(this).TransferTo(
						{
							to:'dia_register',
							className:'transferer2', 
							duration: 400,
							complete: function()
							{
								$('#dia_register').show();
							}
						}
					);
				}
				this.blur();
				return false;
	});

	$('#dia_register').Resizable(
		{
			minWidth: 200,
			minHeight: 60,
			maxWidth: 700,
			maxHeight: 400,
			dragHandle: '#windowTop',
			handlers: {
				se: '#windowResize'
			},
			onResize : function(size, position) {
				$('#windowBottom, #windowBottomContent').css('height', size.height-33 + 'px');
				var windowContentEl = $('#windowContent').css('width', size.width - 25 + 'px');
				if (!document.getElementById('dia_register').isMinimized) {
					windowContentEl.css('height', size.height - 48 + 'px');
				}
			}
		}
	);
	$('#windowClose').bind(
			'click',
			function()
			{
				$('#dia_register').TransferTo(
					{
						to:'js_register',
						className:'transferer2', 
						duration: 400
					}
				).hide();
			}
	);
	$('#reg_email').bind("keyup",function() {
		var email = $(this).val();
		$.ajax({
			type:"post",
			url:"index.php?Controller=Login&Action=RegisterCheck",
			data:"email="+email,
			success:function (msg) {
				$("p.temp_waring").remove();
				$('#reg_email').after("<p class='temp_waring'>"+msg+"</p>");
				$("p.temp_waring").css({border:"1px solid #ee2222",background:"#fcfefc",padding:"3px"});
			}
		})
	});
}
function parseTable(data) {
	var code = thcode = '';
	thcode = "<tr><th><input type='checkbox' id='sel_all' /></th>";
	for(p in data[0]) {
		if(p!=='toJSONString' &&  p!=='uid') 
			thcode +="<th>"+p+"</th>";
	}
	thcode +="</tr>";
	for(var i=0;i<data.length;i++) {
		code +="<tr><td><input type='checkbox' name='sel_all'  value='"+data[i]['uid']+"' /></td>";
		for(p in data[i]) {
			if(p!=='toJSONString' &&  p!=='uid') 
			code +="<td>"+data[i][p]+"</td>";
		}
		code +="</tr>";
	}
	$("#tb").append($(code));
	$("#th").append($(thcode));
}
function selectall(obj) {
	var objname = obj.name;
	var objtype = obj.type;
	var objvalue = obj.value;
	var l = obj.name.length;
	var objcheck = obj.checked;
	if(objtype == "checkbox") {
	for(var i = 0; i< document.forms.length;i++) {
		for(var j=0;j<document.forms[i].elements.length;j++) {
			if(document.forms[i].elements[j].type == objtype && document.forms[i].elements[j].name.substr(0,l) == objname) {
				document.forms[i].elements[j].checked = objcheck;
			}
		}
	}
	}
	if(objtype == "text") {
	for(var i = 0; i< document.forms.length;i++) {
		for(var j=0;j<document.forms[i].elements.length;j++) {
			if(document.forms[i].elements[j].type == objtype && document.forms[i].elements[j].name.substr(0,l) == objname) {
				document.forms[i].elements[j].value = objvalue;
			}
		}
	}
	}
}